@*
* Copyright 2015 Yahoo Inc. Licensed under the Apache License, Version 2.0
* See accompanying LICENSE file.
*@
@import scalaz.{\/}
@(cluster:String, errorOrStatus: kafka.manager.ApiError \/ Option[kafka.manager.model.ActorModel.ReassignPartitions]
)(implicit af: features.ApplicationFeatures, messages: play.api.i18n.Messages, menus: models.navigation.Menus, request:RequestHeader)

@implicitFieldConstructor = @{ b4.vertical.fieldConstructor() }
@theMenu = {
@views.html.navigation.clusterMenu(cluster,"Reassign Partitions","",menus.clusterMenus(cluster)(
    errorOrStatus.toOption.flatten.map(_.clusterContext.clusterFeatures).getOrElse(kafka.manager.features.ClusterFeatures.default)))
}

@renderView(c: String, viewOption: Option[kafka.manager.model.ActorModel.ReassignPartitions]) = {
@viewOption.fold {
<div class="row">
    <div class="alert alert-warning" role="alert">
        No data found for any recent reassign partitions command.
    </div>
</div>
} { repar =>
<div class="row">
    <div class="card">
        <div class="card-header"><h4>Status</h4></div>
        <div class="card-body">
        <table class="table">
            <tbody>
            <tr>
                <td>Submitted:</td>
                <td>@repar.startTime</td>
            <tr>
                <td>Completed:</td>
                <td>@repar.endTime.map(_.toString()).getOrElse("pending")</td>
            </tr>
            </tbody>
        </table>
        </div>
    </div>
</div>
<div class="row">
    <div class="card">
        <div class="card-header"><h4>Request Data</h4></div>
        <div class="card-body">
        <table class="table">
            <thead>
            <tr><th>Topic</th><th>Partition</th><th>Replica Assignment</th></tr>
            </thead>
            <tbody>
            @for(((topic,partNum),assignment) <- repar.sortedTopicPartitionAssignmentList) {
            <tr>
                <td><a href="@routes.Topic.topic(cluster,topic)">@topic</a></td>
                <td>@partNum</td>
                <td>@assignment.mkString("(",",",")")</td>
            </tr>
            }
            </tbody>
        </table>
        </div>
    </div>
</div>
}
}

@main(
    "Reassign Partitions",
    menu = theMenu,
    breadcrumbs=views.html.navigation.breadCrumbs(models.navigation.BreadCrumbs.withViewAndCluster("Reassign Partitions",cluster))) {
<div class="col-md-6 un-pad-me">
    <div class="card">
        <div class="card-header"><h3>Reassign Partitions</h3></div>
        <div class="col-md-12">
            @errorOrStatus.fold[Html](views.html.errors.onApiError(_), renderView(cluster, _))
        </div>
    </div>
</div>
}
